import socket

def calculate(operation, num1, num2):
    if operation == 'add':
        return num1 + num2
    elif operation == 'subtract':
        return num1 - num2
    else:
        return None

def start_server(host, port):
    server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    server_socket.bind((host, port))
    server_socket.listen(1)
    print(f"Server listening on {host}:{port}")

    while True:
        client_socket, client_address = server_socket.accept()
        print(f"Connection established with {client_address[0]}:{client_address[1]}")

        data = client_socket.recv(1024).decode()
        operation, num1, num2 = data.split(',')
        result = calculate(operation, int(num1), int(num2))

        client_socket.send(str(result).encode())
        client_socket.close()

if __name__ == '__main__':
    start_server('localhost', 1234)
